<?php
class MySQL {
    private static $instance = NULL;
    private function __construct() { }
    private function __clone() { }
    public static function getInstance($config) {
        if(!self::$instance) {
            self::$instance = new PDO('mysql:host='.$config['dbhost'].';dbname='.$config['dbname'],$config['dbuser'],$config['dbpass']);
            self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            self::$instance->query('set names utf8');//设置字符集utf8
        }
        return self::$instance;
    }
}